package com.zqj.project.factory;

import com.zqj.project.common.database.mybatis.conditions.Wraps;
import com.zqj.project.common.database.mybatis.conditions.query.LbqWrapper;
import com.zqj.project.entity.PhonePO;
import com.zqj.project.model.Phone;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @Description: PhoneFactory
 * @Author: 22001010704 Zhang Qijian
 * @CreateTime: 2024/12/8 18:53
 * @Version: 1.0
 */
public class PhoneFactory {

    private PhoneFactory() {
        throw new IllegalStateException("Utility Class");
    }

    public static LbqWrapper<PhonePO> lbqWrapper(Phone phone) {
        return Wraps.<PhonePO>lbQ().like(StringUtils.isNotBlank(phone.getName()), PhonePO::getName, phone.getName())
                .like(StringUtils.isNotBlank(phone.getBrand()), PhonePO::getBrand, phone.getBrand())
                .like(StringUtils.isNotBlank(phone.getCpu()), PhonePO::getCpu, phone.getCpu())
                .like(StringUtils.isNotBlank(phone.getScreen()), PhonePO::getScreen, phone.getScreen())
                .like(StringUtils.isNotBlank(phone.getBattery()), PhonePO::getBattery, phone.getBattery())
                .like(StringUtils.isNotBlank(phone.getCamera()), PhonePO::getCamera, phone.getCamera())
                .like(StringUtils.isNotBlank(phone.getDescription()), PhonePO::getDescription, phone.getDescription())
                .ge(Objects.nonNull(phone.getLowerPrice()), PhonePO::getPrice, phone.getLowerPrice())
                .le(Objects.nonNull(phone.getUpperPrice()), PhonePO::getPrice, phone.getUpperPrice())
                .orderByDesc(PhonePO::getCreateTime);
    }

}